import type { Patient, User, UserInfo, initPatient } from '@/types/user'
import { request } from '@/utils/request'
//密码登录
export const loginByPassword = (mobile: string, password: string) =>
  request<User>('/login/password', 'POST', { mobile, password })
// login登录register注册changeMobile更换手机号forgetPassword找回密码,bindMobile绑定三方登录，区分验证码
type CodeType =
  | 'login'
  | 'register'
  | 'changeMobile'
  | 'forgetPassword'
  | 'bindMobile'
//获取验证码
export const getMobileCode = (mobile: string, type: CodeType) =>
  request<{ code: string }>('/code', 'GET', { mobile, type })

//短信验证码登录
export const loginByCode = (mobile: string, code: string) =>
  request<User>('/login', 'post', { mobile, code })
//个人用户信息
export const getUserInfo = () => request<UserInfo>('patient/myUser', 'get')
//家庭信息
export const getPatientList = () => request<Patient[]>('/patient/mylist', 'get')
//添加患者
export const addPatient = (patient: initPatient) =>
  request('/patient/add', 'post', patient)
//编辑患者
export const editPatient = (patient: initPatient) =>
  request('/patient/update', 'put', patient)
//删除患者信息
export const delPatient = (id: string) =>
  request(`/patient/del/${id}`, 'DELETE')
